home *** CD-ROM | disk | FTP | other *** search
- Path: svnews.ubinet.ubs.com!ubszh!ian.johnston@ubs.com
- From: ian.johnston@ubs.com (Ian Johnston (by ubsswop))
- Newsgroups: comp.lang.c++
- Subject: Re: C++ meta-problem
- Date: 1 Apr 1996 13:51:42 GMT
- Organization: UBS
- Distribution: world
- Message-ID: <4jon1e$ka@ubszh.fh.zh.ubs.com>
- References: <4jmtlg$smm@baskerville.CS.Arizona.EDU>
- NNTP-Posting-Host: nol2179.fh.zh.ubs.com
-
- In article <4jmtlg$smm@baskerville.CS.Arizona.EDU>, kdb@CS.Arizona.EDU (Koen De Bosschere) writes:
- |> In order to prevent to write an iterator for every operation
- |> I want to perform on a list, I tried to write a kind of
- |> meta-iterator that would apply a particular method to
- |> all listnodes. For some reason, I cannot execute a
- |> function variable on an object. Does anyone has an
- |> idea how I can solve this problem?
-
- [...]
-
- |> void iterate(testclass *root, void (testclass::*f)())
- |> {
- |> testclass *p = root;
- |> while (p) {
- |> p->f(); // <--- here the compiler generates an error (see below)
- |> p = p->getnext();
- |> }
- |> }
-
-
- To solve this problem, try
-
- p->*f();
-
-
- However, this is not a very general solution. You may want to look
- at function objects (as being discussed in another thread right now).
-
- Ian
-
-